home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / clipper / nannws34.arc / MAKLNK.PRG < prev    next >
Text File  |  1989-01-01  |  6KB  |  221 lines

  1. * Program: Maklnk.prg
  2. * Author:  F. Scott Barker
  3. *          Associated Computer Specialists, Inc.
  4. * Version: Clipper Summer '87
  5. * Note(s): This program creates a rudimentary MAK and LNK
  6. *          file, as is.  It works without overlays and
  7. *          with Tlink. [Ed. note: You can link Clipper
  8. *          applications with Borland's Turbo Link versions 1.0
  9. *          and 1.1.  Version 2.0 will not work.]
  10. *
  11. *          This program takes the prg files listed in current dir
  12. *          and with the given name creates the Make definition
  13. *          file and LNK file.  If the name for the MAK file is not
  14. *          found in the directory, it will asked for the main
  15. *          program name.  This must be given for linking purposes.
  16. *
  17. PARAMETER mName
  18. CLEAR
  19. IF TYPE("mName") = [U]
  20.    mName = SPACE(8)
  21.    * Get name of make definition file to create.
  22.    @ 10,5 SAY [Enter initials of system: ] GET mName PICT [@!]
  23.    READ
  24.    IF EMPTY(mName)           && If none entered go home.
  25.       CLEAR
  26.       RETURN
  27.    ENDIF
  28. ENDIF
  29. mName = TRIM(mName)
  30. makname = TRIM(mName) + [.MAK]
  31. IF FILE(makname)             && Make sure MAK file is not
  32.                              ** already there.
  33.    mOver = .N.
  34.    @ 12,5 SAY makname + [ Already exists, do you wish to ] +;
  35.       [overwrite? ] GET mOver PICT [Y]
  36.    READ
  37.    IF ! mOver
  38.       CLEAR
  39.       RETURN
  40.    ENDIF
  41. ENDIF
  42. prgcnt = ADIR("*.PRG")       && Get # of prog files in current
  43.                              ** dir to include.
  44.  
  45. * Declare prg file array, # of sections there will be.
  46. DECLARE aprg[prgcnt], mSTR[(prgcnt/6) + 1]
  47. ADIR("*.PRG", aprg)          && Load and sort prg array.
  48. ASORT(aprg)
  49.  
  50. * This next section puts the head program into the first position
  51. * in the file array, if there is not a file matching mak def. name
  52. * inputed, you will be prompted to name the head, or main calling
  53. * program.
  54. mNamePos = ASCAN(aprg, mName + [.PRG])
  55. DO WHILE mNamePos = 0 .AND. LASTKEY() # 27
  56.    mHead = SPACE(8)
  57.    TONE(100,10)
  58.    @ 14,5 SAY [Problem, you need to enter ] + ;
  59.       [name of head program: ];
  60.       GET mHead PICT [@!]
  61.    READ
  62.    mHead = TRIM(mHead)
  63.    mNamePos = ASCAN(aprg ,mHead + [.PRG])
  64. ENDDO
  65. * If no calling program go home.
  66. IF mNamePos = 0
  67.    RETURN
  68. ENDIF
  69. * Actual movement to front of file array.
  70. mTemp = aprg[1]
  71. aprg[1] = aprg[mNamePos]
  72. aprg[mNamePos] = mTemp
  73.  
  74. * Create file whatever.mak.
  75. infile = FCREATE(makname)
  76. * Init section counter.
  77. sect = 1
  78. * Init prgs per section counter.
  79. numprgs = 0
  80. * Init First section string.
  81. mStr[sect] = [sect1 = ]
  82.  
  83. * This section writes the macros for OBJs.
  84. FOR I = 1 TO prgcnt
  85.    * This grabs the name for each file and
  86.    * slaps OBJ on.
  87.    mStr[sect] = mStr[sect] + ;
  88.       SUBSTR(aprg[I],1,AT([.],aprg[I]))+[OBJ ]
  89.    * If the maximum number of files per
  90.    * section is reached, write it to disk and
  91.    * init the next section.
  92.    IF numprgs = 6  
  93.       FWRITE(infile, TRIM(mStr[sect]) + ;
  94.          CHR(13) + CHR(10))
  95.       IF I = prgcnt
  96.          EXIT
  97.       ENDIF
  98.       sect = sect + 1
  99.       mStr[sect] = [sect]+STR(sect,1) + [ = ]
  100.       numprgs = 1
  101.    ENDIF
  102.    * If all prgs are processed,
  103.    * write last section.
  104.    IF I = prgcnt
  105.       FWRITE(infile, TRIM(mStr[sect]) + ;
  106.          CHR(13) + CHR(10))
  107.    ENDIF
  108.    * Increment # of prgs per section.
  109.    numprgs = numprgs + 1
  110. NEXT
  111.  
  112. * Next section just writes a blank line, and
  113. * the compile commands.
  114. mTxt = CHR(13) + CHR(10)
  115. FWRITE(infile, mTxt)
  116. mTxt = ".prg.obj:" + CHR(13) + CHR(10)
  117. FWRITE(infile, mTxt)
  118. mTxt = "clipper $* -m -q" + CHR(13) + CHR(10)
  119. FWRITE(infile, mTxt)
  120. mTxt = "  if errorlevel 1 pause Error in " +;
  121.    "compilation. Break and fix before " +;
  122.    "continuing." + CHR(13) + CHR(10)
  123. FWRITE(infile, mTxt)
  124. mTxt = CHR(13) + CHR(10)
  125. FWRITE(infile, mTxt)
  126.  
  127. * This section lists the prg to OBJ
  128. * dependencies.
  129. mTxt = [# PRG -> OBJ creation] + CHR(13) + ;
  130.    CHR(10)
  131. FOR I = 1 TO prgcnt
  132.    mObj = SUBSTR(aprg[I],1,AT([.],aprg[I])) +;
  133.       [OBJ]
  134.    mTxt = mObj + SPACE(13-LEN(mObj)) + [: ] +;
  135.       aprg[I] + CHR(13) + CHR(10)
  136.    FWRITE(infile, mTxt)
  137. NEXT
  138. mTxt = CHR(13) + CHR(10)
  139. FWRITE(infile, mTxt)
  140. mTxt = [# .EXE file] + CHR(13) + CHR(10)
  141. FWRITE(infile, mTxt)
  142.  
  143. * This section creates the exe -> section
  144. * dependencies.  Tlink is used.
  145. mTxt = mName + [.EXE :]
  146. FOR I = 1 TO sect
  147.    mTxt = mTxt + [ $(sect] + STR(I,1) + [)]
  148. NEXT
  149. mTxt = mTxt + CHR(13) + CHR(10)
  150. FWRITE(infile, mTxt)
  151. mTxt = [  break on] + CHR(13) + CHR(10)
  152. FWRITE(infile, mTxt)
  153. mTxt = [  tlink @] + mName + [.LNK] + ;
  154.    CHR(13) + CHR(10)
  155. FWRITE(infile, mTxt)
  156. FCLOSE(makname)
  157.  
  158. * All done with the Mak file, time for the LNK
  159. * file again, this is done with Tlink only.
  160. lnkname = mName + [.LNK]
  161.  
  162. * Make sure LNK file is not already there.
  163. IF FILE(lnkname)
  164.    mOver = .N.
  165.    @ 18,5 SAY lnkname + [ Already exists, ]+;
  166.       [do you wish to overwrite? ];
  167.       GET mOver PICT [Y]
  168.    READ
  169.    IF ! mOver
  170.       CLEAR
  171.       RETURN
  172.    ENDIF
  173. ENDIF
  174. infile = FCREATE(lnkname)
  175.  
  176. * Time to list the files for linking.
  177. FOR I = 1 TO sect
  178.    mTxt = SUBSTR(mStr[I],9) + [ +] + ;
  179.       CHR(13) + CHR(10)
  180.    FWRITE(infile, mTxt)
  181. NEXT
  182.  
  183. * Check to see if any other OBJ files are used
  184. * and add them in.
  185. mTxt = []
  186. DO WHILE .T.
  187.    mOther = SPACE(20)
  188.    @ 20,5 SAY [Enter OBJ files with paths, ]+;
  189.       [<CR> when done: ] GET mOther
  190.    READ
  191.    IF EMPTY(mOther)
  192.       EXIT
  193.    ENDIF
  194.    mTxt = mTxt + TRIM(mOther) + [ ]
  195. ENDDO
  196.  
  197. * Debug is added; you may want to alter.
  198. mTxt = mTxt + [DEBUG.OBJ] + CHR(13) + CHR(10)
  199. FWRITE(infile, mTxt)
  200.  
  201. * Check to see if any LIB files are used and
  202. * add them in.
  203. mLibTxt = []
  204. DO WHILE .T.
  205.    mOther = SPACE(20)
  206.    @ 22,5 SAY [Enter lib files with paths, ]+;
  207.       [<CR> when done: ] GET mOther
  208.    READ
  209.    IF EMPTY(mOther)
  210.       EXIT
  211.    ENDIF
  212.    mLibTxt = mLibTxt + TRIM(mOther) + [ ]
  213. ENDDO
  214. mTxt = mName + [.EXE,,] + mLibTxt + CHR(13) +;
  215.    CHR(10)
  216. FWRITE(infile, mTxt)
  217. FCLOSE(lnkname)
  218. CLEAR
  219. @ 1,0 SAY [Creation complete!]
  220. RETURN
  221.